package com.zhx.learn.stream.cart;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：zhanghaixuan
 * @date ：Created in 2019-09-18 14:16
 * 用途         ： 购物车服务类
 */
public class  CartService {

    private static List<Sku> cartList = new ArrayList<Sku>() {
        {
            add(new Sku(654032, "无人机",
                    4999.00, 1,
                    4999.00, SkuCategoryEnum.ELECTRONICS));

            add(new Sku(642934, "VR一体机",
                    2299.00, 1,
                    2299.00, SkuCategoryEnum.ELECTRONICS));

            add(new Sku(645321, "纯色衬衫",
                    409.00, 3,
                    1227.00, SkuCategoryEnum.CLOTHING));

            add(new Sku(654327, "牛仔裤",
                    528.00, 1,
                    528.00, SkuCategoryEnum.CLOTHING));

            add(new Sku(675489, "跑步机",
                    2699.00, 1,
                    2699.00, SkuCategoryEnum.SPORTS));

            add(new Sku(644564, "Java编程思想",
                    79.80, 1,
                    79.80, SkuCategoryEnum.BOOKS));

            add(new Sku(678678, "Java核心技术",
                    149.00, 1,
                    149.00, SkuCategoryEnum.BOOKS));

            add(new Sku(697894, "算法",
                    78.20, 1,
                    78.20, SkuCategoryEnum.BOOKS));

            add(new Sku(696968, "TensorFlow进阶指南",
                    85.10, 1,
                    85.10, SkuCategoryEnum.BOOKS));
        }
    };

    /**
     * 返回所有商品列表
     * @return 商品列表
     */
    public static List<Sku> getCartList() {
        return cartList;
    }

    /**
     * version 1.0.0
     * @param list 参数
     * @return 所有电子产品类的商品
     */
    public static List<Sku> filterElectronicsSkus(List<Sku> list){
        ArrayList<Sku> skus = new ArrayList<>();

        for (Sku sku : list) {
            if (sku.getSkuCategory().equals(SkuCategoryEnum.ELECTRONICS)) {
                skus.add(sku);
            }
        }

        return skus;
    }


    /**
     * version 2.0.0
     * @param list 参数
     * @return 根据商品类别获取相应的商品
     */
    public static List<Sku> filterSkusByCategory(List<Sku> list,SkuCategoryEnum skuCategoryEnum){
        ArrayList<Sku> skus = new ArrayList<>();

        for (Sku sku : list) {
            if (sku.getSkuCategory().equals(skuCategoryEnum)) {
                skus.add(sku);
            }
        }

        return skus;
    }
}

